import Vue from 'vue'
import {navKey} from '@/env'

const Watcher = Vue.extend({
  data () {
    return {
      states: {
        navs: []
      }
    }
  },
  watch: {
    'states.navs': {
      deep: true,
      handler (val) {
        Vue.ls.set(navKey, val)
      }
    }
  }
})

const createStore = (initialState = {}) => {
  const store = new Watcher()

  Object.keys(initialState).forEach(key => {
    store.states[key] = initialState[key]
  })
  return store
}

export {createStore}

export default Watcher
